package com.waitingresult.h2.controller;

import com.waitingresult.h2.entity.Liquor;
import com.waitingresult.h2.entity.Student;
import com.waitingresult.h2.mapper.LiquorMapper;
import com.waitingresult.h2.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: WangShuai
 * @CreateTime: 2023-02-07  15:02
 * @Description:
 * @Version: 1.0
 */
@RestController
public class DemoController {
    @Resource
    private StudentService studentService;

    @GetMapping("saveBatch")
    public boolean saveBatch() {
        ArrayList<Student> students = new ArrayList<>();
        for (int i = 0; i < 10000; i++) {
            int i1 = 10000000 + i;
            Student student = new Student();
            student.setName("TestName" + i);
            student.setPhone(i1 + "");
            students.add(student);
            if(students.size() > 1000){
                studentService.saveBatch(students);
                students.clear();
            }
        }
        return true;
    }
    @GetMapping("getById")
    public Student getById(Integer id) {
        return studentService.getById(id);
    }
    @Autowired
    private LiquorMapper liquorMapper;

    @GetMapping("/find")
    public List<Liquor> findLiquor(){
        return liquorMapper.selectList(null);
    }
}
